package com.ruoyi.project.system.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.project.system.domain.SysMoments;
import com.ruoyi.project.system.service.ISysMomentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysMomentComment;
import com.ruoyi.project.system.service.ISysMomentCommentService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 平台瞬间评论Controller
 *
 * @author jjp
 * @date 2020-04-14
 */
@RestController
@Api(description = "平台精彩瞬间评论")
@RequestMapping("/system/comment")
public class SysMomentCommentController extends BaseController
{
    @Autowired
    private ISysMomentCommentService sysMomentCommentService;

    @Autowired
    private ISysMomentsService sysMomentsService;

    /**
     * 查询平台瞬间评论列表
     */
    @PreAuthorize("@ss.hasPermi('system:comment:list')")
    @ApiOperation("查询平台瞬间评论列表")
    @GetMapping("/list")
    public TableDataInfo list(SysMomentComment sysMomentComment)
    {
        startPage();
        List<SysMomentComment> list = sysMomentCommentService.selectSysMomentCommentList(sysMomentComment);
        return getDataTable(list);
    }



    /**
     * 获取平台瞬间评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:comment:query')")
    @ApiOperation("获取平台瞬间评论详细信息")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId) {
        SysMomentComment sysMomentComment = sysMomentCommentService.selectSysMomentCommentById(commentId);
        SysMoments sysMoments = new SysMoments();
        sysMoments.setCommentId(commentId);
        List<SysMoments> sysMoments1 = sysMomentsService.selectSysMomentsList(sysMoments);
        Map<Object, Object> map = new HashMap<>();
        map.put(sysMomentComment, sysMoments1);
        return AjaxResult.success(map);
    }

    /**
     * 新增平台瞬间评论
     */
    @PreAuthorize("@ss.hasPermi('system:comment:add')")
    @ApiOperation("新增平台瞬间评论")
    @Log(title = "平台瞬间评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMomentComment sysMomentComment)
    {
        return toAjax(sysMomentCommentService.insertSysMomentComment(sysMomentComment));
    }

    /**
     * 修改平台瞬间评论
     */
    @PreAuthorize("@ss.hasPermi('system:comment:edit')")
    @ApiOperation("修改平台瞬间评论")
    @Log(title = "平台瞬间评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMomentComment sysMomentComment)
    {
        return toAjax(sysMomentCommentService.updateSysMomentComment(sysMomentComment));
    }

    /**
     * 删除平台瞬间评论
     */
    @PreAuthorize("@ss.hasPermi('system:comment:remove')")
    @Log(title = "平台瞬间评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds)
    {
        return toAjax(sysMomentCommentService.deleteSysMomentCommentByIds(commentIds));
    }


    /**
     * 获取平台瞬间评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:comment:query')")
    @ApiOperation("获取单个平台瞬间评论详细信息列表")
    @GetMapping(value = "/findMoment/{momentId}")
    public TableDataInfo findMoment(@PathVariable("momentId") Long momentId)
    {
        startPage();
        List<SysMomentComment> sysMomentComments = sysMomentCommentService.selectSysMomentId(momentId);
        return getDataTable(sysMomentComments);
    }
}
